package Test;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

import java.util.Arrays;
import java.util.List;

public class TestSparkSortBy {
    public static void main(String[] args) {
        SparkConf sparkConf = new SparkConf().setAppName("spark demo").setMaster("local");
        JavaSparkContext sc = new JavaSparkContext(sparkConf);
         // parallelize 并行化数据集
        JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 3, 5, 6, 7, 4, 9, 10), 2);

        Function<Integer, Integer> function = new Function<Integer, Integer>() {
            @Override
            public Integer call(Integer integer) throws Exception {
                return integer;
            }
        };
        JavaRDD<Integer> rdd2 = rdd.sortBy(function, false, rdd.getNumPartitions());

        List<Integer> res = rdd2.collect();
        for (Integer i : res) {
            System.out.println(i);
        }

    }
}
